package com.gec.hawaste.controller;


import com.gec.hawaste.entity.AppVersion;
import com.gec.hawaste.service.IAppVersionService;
import com.gec.hawaste.utils.PageInfo;
import com.gec.hawaste.utils.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lisongsong
 * @since 2022-04-21
 */
@RestController
@RequestMapping("manager/app")
public class AppVersionController {

    @Autowired
    private IAppVersionService iAppVersionService;

    //查询全部appVersion/数据·带有分页功能
    @RequestMapping("select")
    public ResultBean<AppVersion> select(@RequestParam("current") int current,@RequestParam("size") int size){

        PageInfo<AppVersion> pageInfo = new PageInfo<>(current, size);
        pageInfo= this.iAppVersionService.page(pageInfo);
        pageInfo.setNavigatePage();
        return ResultBean.ok(pageInfo);
    }

    //根据id去查询当前的一条数据
    @RequestMapping("selectOne")
    public ResultBean<AppVersion> selectOne(Long id){
        AppVersion appVersion = this.iAppVersionService.getById(id);
        System.out.println(appVersion);
        return ResultBean.ok(appVersion);
    }

    // 添加 和更新的接口  // 有主键就更新，无主键就添加

    @RequestMapping("saveOrUpdate")
    public ResultBean saveOrUpdate(@RequestBody AppVersion appVersion){
        this.iAppVersionService.saveOrUpdate(appVersion);
        return ResultBean.ok();
    }
    // 根据id 去删除
    @RequestMapping("delete")
    public ResultBean delete(long id){
        this.iAppVersionService.removeById(id);
        return ResultBean.ok();
    }

}
